/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CrearRespuestaForo.java
 *
 * Created on 27-mar-2012, 22:20:57
 */
package sistemadeproyectos;

import java.sql.SQLException;
import java.util.*;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

/**
 *
 * @author giancarlo
 */
public class CrearRespuestaForo extends javax.swing.JDialog {

    private HiloForo Foro;
        
    /** Creates new form CrearRespuestaForo */
    public CrearRespuestaForo(java.awt.Frame parent, boolean modal, 
            HiloForo Foro) {
        super(parent, modal);
        initComponents();
        this.Foro = Foro;
        jLabelAutor.setText((this.Foro).getAutor());
        jLabelAsunto.setText((this.Foro).getAsunto());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelAsunto = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabelAutor = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButtonCancelar = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jButtonAgregar = new javax.swing.JButton();
        jPanelArea = new javax.swing.JScrollPane();
        jTexto = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sistemadeproyectos.SistemadeproyectosApp.class).getContext().getResourceMap(CrearRespuestaForo.class);
        jLabelAsunto.setText(resourceMap.getString("jLabelAsunto.text")); // NOI18N
        jLabelAsunto.setName("jLabelAsunto"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabelAutor.setText(resourceMap.getString("jLabelAutor.text")); // NOI18N
        jLabelAutor.setName("jLabelAutor"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel2.setInheritsPopupMenu(false);
        jLabel2.setName("jLabel2"); // NOI18N

        jButtonCancelar.setText(resourceMap.getString("jButtonCancelar.text")); // NOI18N
        jButtonCancelar.setName("jButtonCancelar"); // NOI18N
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jButtonAgregar.setText(resourceMap.getString("jButtonAgregar.text")); // NOI18N
        jButtonAgregar.setName("jButtonAgregar"); // NOI18N
        jButtonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAgregarActionPerformed(evt);
            }
        });

        jPanelArea.setName("jPanelArea"); // NOI18N

        jTexto.setColumns(20);
        jTexto.setLineWrap(true);
        jTexto.setRows(5);
        jTexto.setWrapStyleWord(true);
        jTexto.setName("jTexto"); // NOI18N
        jPanelArea.setViewportView(jTexto);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addComponent(jButtonAgregar)
                        .addGap(47, 47, 47)
                        .addComponent(jButtonCancelar)))
                .addContainerGap(116, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(137, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(130, 130, 130))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelArea, javax.swing.GroupLayout.PREFERRED_SIZE, 424, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel6)
                    .addGap(32, 32, 32)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabelAsunto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabelAutor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap(289, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(69, 69, 69)
                .addComponent(jLabel3)
                .addGap(27, 27, 27)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelArea, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAgregar)
                    .addComponent(jButtonCancelar))
                .addContainerGap(32, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(56, 56, 56)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(jLabelAutor))
                    .addGap(18, 18, 18)
                    .addComponent(jLabelAsunto)
                    .addContainerGap(257, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButtonCancelarActionPerformed

    private void jButtonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAgregarActionPerformed
        // TODO add your handling code here:
         String texto = "";
         try { texto = jTexto.getText(); }
         catch (NullPointerException e) 
         {
            JOptionPane.showMessageDialog(null, "El contenido no puede ser vacio", "Datos incompletos", JOptionPane.ERROR_MESSAGE);
            jTexto.requestFocus();
         }
         if (!(texto.equals(""))) {
            //try {
                    java.util.Date d = new java.util.Date();
                    Calendar c = new GregorianCalendar();
                    c.setTime(d);

                    String fecha = (Integer.toString(c.get(Calendar.DATE)) +
                        "/" + Integer.toString(c.get(Calendar.MONTH)) +
                        "/" + Integer.toString(c.get(Calendar.YEAR)));
                      
                    String hora = (Integer.toString(c.get(Calendar.HOUR_OF_DAY)) +
                        ":" + Integer.toString(c.get(Calendar.MINUTE)) +
                        ":" + Integer.toString(c.get(Calendar.SECOND)));
                    //ASUMIMOS QUE NO SE POSTEARAN DOS RESPUESTA POR EL
                    //MISMO USUARIO EN EL MISMO EQUIPO AL MISMO TIEMPO
                    BDAdmin motor = new BDAdmin("INSERT INTO RESPUESTA_FORO VALUES('" 
                        + (this.Foro).getAutor() + "','" + fecha + "','" + hora + "','" 
                        + texto + "','" + (this.Foro).getEquipo() + "','" 
                        + (this.Foro).getAsunto() + "')");                        
                    motor.actualizar();
                    JOptionPane.showMessageDialog(this, "La respuesta ha"
                        + " sido publicada correctamente!","Respuesta Publicada", 
                        JOptionPane.INFORMATION_MESSAGE);
                    ((VerRespuestasForo)this.getParent()).mostrarPublicaciones();
                    this.dispose();
                    
                    motor.cerrar();
            //}
            //catch(SQLException sqle){
              //      sqle.printStackTrace();
            //}                
         }
         else {
            JOptionPane.showMessageDialog(null, "El contenido no puede ser vacio", "Datos incompletos", JOptionPane.ERROR_MESSAGE);
                jTexto.requestFocus();   
         }
    }//GEN-LAST:event_jButtonAgregarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CrearRespuestaForo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CrearRespuestaForo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CrearRespuestaForo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CrearRespuestaForo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                /*CrearRespuestaForo dialog = new CrearRespuestaForo(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);*/
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAgregar;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabelAsunto;
    private javax.swing.JLabel jLabelAutor;
    private javax.swing.JScrollPane jPanelArea;
    private javax.swing.JTextArea jTexto;
    // End of variables declaration//GEN-END:variables
}
